<template>
    <object id="view1" type="application/x-eloamplugin" width="600" height="300" name="view"></object> 
</template>
<script>
export default {
    name:'high-shot',
    methods:{
        plugin(){

            return document.getElementById('view1');
        },
        MainView()
        {
            return document.getElementById('view1');
        },

        AssistView()
        {
            return document.getElementById('view2');
        },

        thumb1()
        {
            return document.getElementById('thumb1');
        },
        addEvent(obj, name, func)
        {
            if (obj.attachEvent) {
                obj.attachEvent("on"+name, func);
            } else {
                obj.addEventListener(name, func, false); 
            }
        },
        loadCard(){
             this.addEvent(this.plugin(), 'Ocr', function(flag, ret)
            {
                if (1 == flag && 0 == ret)
                {
                    var ret = this.plugin().Global_GetOcrPlainText(0);
                    alert(ret);
                }
            });
    
            this.addEvent(this.plugin(), 'IdCard', function(ret)
            {
                if (1 == ret)
                {
                    var str = GetTimeString() + "：";
            
                    for(var i = 0; i < 16; i++)
                    {
                        str += this.plugin().Global_GetIdCardData(i + 1);
                        str += ";";				
                    }
        
                    document.getElementById("idcard").value=str;	
                    
                    var image = this.plugin().Global_GetIdCardImage(1);//1表示头像， 2表示正面， 3表示反面 ...
                    this.plugin().Image_Save(image, "C:\\idcard.jpg", 0);
                    this.plugin().Image_Release(image);
                    
                    document.getElementById("idcardimg").src= "C:\\idcard.jpg";
                    idcardBoikey = this.plugin().Global_GetIdCardFingerprintEx(1);
                }
            });

            this.addEvent(this.plugin(), 'Biokey', function(ret)
            {
                if (4 == ret)
                {
                    // 采集模板成功
                    var mem = this.plugin().Global_GetBiokeyTemplateData();
                    if (mem)
                    {
                        if (this.plugin().Memory_Save(mem, "C:\\1.tmp"))
                        {
                            document.getElementById("biokey").value="获取模板成功，存储路径为C:\\1.tmp";
                        }						
                        this.plugin().Memory_Release(mem);
                    }
            
                    var img = this.plugin().Global_GetBiokeyImage();
                    this.plugin().Image_Save(img, "C:\\BiokeyImg1.jpg", 0);
                    this.plugin().Image_Release(img);
            
                    document.getElementById("BiokeyImg1").src= "C:\\BiokeyImg1.jpg";					
                    alert("获取指纹模板成功");
                }
                else if (8 == ret)
                {
                    var mem = this.plugin().Global_GetBiokeyFeatureData();
                    if (mem)
                    {
                        if (this.plugin().Memory_Save(mem, "C:\\2.tmp"))
                        {
                            document.getElementById("biokey").value="获取特征成功，存储路径为C:\\2.tmp";
                        }						
                        this.plugin().Memory_Release(mem);
                    }
            
                    var img = this.plugin().Global_GetBiokeyImage();
                    this.plugin().Image_Save(img, "C:\\BiokeyImg2.jpg", 0);
                    this.plugin().Image_Release(img);
            
                    document.getElementById("BiokeyImg2").src= "C:\\BiokeyImg2.jpg";
                    alert("获取指纹特征成功");
                }
                else if (9 == ret)
                {
                    document.getElementById("biokey").value += "\r\n刷的不错！";
                }
                else if (10 == ret)
                {
                    document.getElementById("biokey").value+= "\r\n图像质量太差！";
                }
                else if (11 == ret)
                {
                    document.getElementById("biokey").value+= "\r\n图像点数太少！";
                }
                else if (12 == ret)
                {
                    document.getElementById("biokey").value+= "\r\n太快！";
                }
                else if (13 == ret)
                {
                    document.getElementById("biokey").value+= "\r\n太慢！";
                }
                else if (14 == ret)
                {
                    document.getElementById("biokey").value+= "\r\n其它质量问题！";
                }				
            });
    
            this.addEvent(this.plugin(), 'Reader', function(type, subtype)
            {
                var str = "";
                if (4 == type)
                {
                    if( 0 == subtype)//接触式CPU卡
                    {
                        str += "[接触式CPU卡][银行卡号]:";
                        str += this.plugin().Global_ReaderGetCpuCreditCardNumber();
                    }
                    else if( 1 == subtype)//非接触式CPU卡
                    {
                        str += "[非接触式CPU卡] :";
                        str += "[Id]:";
                        str += this.plugin().Global_ReaderGetCpuId();
                        str += "[银行卡号]:";
                        str += this.plugin().Global_ReaderGetCpuCreditCardNumber();
                        
                        str += "[磁道数据]:";
                        str +=this.plugin().Global_CpuGetBankCardTrack();//磁道数据
                        
                        str += "[交易记录]:";
                        var n = this.plugin().Global_CpuGetRecordNumber();//交易条数
                        for(var i = 0; i < n; i++)
                        {
                            str += this.plugin().Global_CpuGetankCardRecord(i);
                            str + ";";
                        }			
                    }							
                }
                else if (2 == type)
                {
                    str += "[M1卡] Id:";
                    str += this.plugin().Global_ReaderGetM1Id();
                }
                else if (3 == type)
                {
                    str += "[Memory卡] Id:";
                    str += this.plugin().Global_ReaderGetMemoryId();	
                }
                else if (5 == type)
                {
                    str += "[社保卡] :";
                    str += this.plugin().Global_ReaderGetSocialData(1);
                    str += this.plugin().Global_ReaderGetSocialData(2);
                }
                document.getElementById("reader").value=str;
            });
    
            this.addEvent(this.plugin(), 'Mag', function(ret)
            {
                var str = "";
        
                str += "[磁卡卡号] ";
                str += this.plugin().Global_MagneticCardGetNumber();
        
                str += "[磁道数据]";		

                str += "磁道1:";					
                str += this.plugin(). Global_MagneticCardGetData(0);	
                str += "磁道2:";
                str += this.plugin(). Global_MagneticCardGetData(1);	
                str += "磁道3:";
                str += this.plugin(). Global_MagneticCardGetData(2);	
        
                document.getElementById("mag").value=str;
            });
    
            this.addEvent(this.plugin(), 'ShenZhenTong', function(ret)
            {
                var str = "";
        
                str += "[深圳通卡号] ";
                str += this.plugin().Global_GetShenZhenTongNumber();
                
                str += "[金额:] ";
                str += this.plugin().Global_GetShenZhenTongAmount();
        
                str += "[交易记录:]";

                var n = this.plugin().Global_GetShenZhenTongCardRecordNumber();
                for(var i = 0; i < n ; i++)
                {			
                    str += this.plugin().Global_GetShenZhenTongCardRecord( i);	
                    str += ";";	
                }			
                document.getElementById("shenzhentong").value=str;
            });			
    
            this.addEvent(this.plugin(), 'MoveDetec', function(video, id)
            {
                // 自动拍照事件	
            });
    
            this.addEvent(this.plugin(), 'Deskew', function(video, view, list)
            {
                // 纠偏回调事件
                var count = this.plugin().RegionList_GetCount(list);				
                for (var i = 0; i < count; ++i)
                {				
                    var region = this.plugin().RegionList_GetRegion(list, i);
            
                    var x1 = this.plugin().Region_GetX1(region);
                    var y1 = this.plugin().Region_GetY1(region);
            
                    var width = this.plugin().Region_GetWidth(region);
                    var height = this.plugin().Region_GetHeight(region);
            
                    this.plugin().Region_Release(region);
                }
        
                this.plugin().RegionList_Release(list);
            });
        
            var title = document.title;
            document.title = title + this.plugin().version;
        
            this.MainView().Global_SetWindowName("view");
            this.AssistView().Global_SetWindowName("view");
            this.thumb1().Global_SetWindowName("thumb");

            var ret;
            ret = this.plugin().Global_InitDevs();
            if(ret)
            {
                //进行人脸识别初始化时，视频应处于关闭状态
                    this.plugin().InitFaceDetect();
            }
            
            if( !this.plugin().Global_VideoCapInit())
            {
                alert("初始化失败！");
            }
        },
        ReadIDCard(){
            this.loadCard();
            if(this.plugin().Global_InitIdCard())
            {
                var ret = this.plugin().Global_ReadIdCard();
                if(ret)
                {
                    //var str = GetTimeString() + "：";
                    var data={};
                    data.NameA=this.plugin().Global_GetIdCardData(1);
                    data.Sex=this.plugin().Global_GetIdCardData(2);
                    data.mz=this.plugin().Global_GetIdCardData(3);
                    data.Born=this.plugin().Global_GetIdCardData(4)+this.plugin().Global_GetIdCardData(5)+this.plugin().Global_GetIdCardData(6);
                    data.Address=this.plugin().Global_GetIdCardData(7);
                    data.CardNo=this.plugin().Global_GetIdCardData(8);
                    data.ga=this.plugin().Global_GetIdCardData(9);//发证公安
                    data.startDate=this.plugin().Global_GetIdCardData(10)+"-"+this.plugin().Global_GetIdCardData(11)+"-"+this.plugin().Global_GetIdCardData(12);//发证公安
                    data.endDate=this.plugin().Global_GetIdCardData(12)+"-"+this.plugin().Global_GetIdCardData(13)+"-"+this.plugin().Global_GetIdCardData(14);//发证公安
                    console.log("获取身份证信息=========================");
                    console.log(data);
                }
                else
                {
                    document.getElementById("idcard").value= "读取二代证失败！";
                }
                
                this.plugin().Global_DeinitIdCard();
                
            }
            else
            {
                alert("初始化二代证阅读器失败！");
                
            }
            return "Y";
        }
    }
}
</script>